﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebAsbesto.Clientes
{
    public partial class Cliente_Alta : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
         if (Session["User"] != "1")
            Response.Redirect("Login/Login.aspx");
         else if (Session["User"] == "1")
                {
                            //PAGE LOAD ACA!
                }
        }

        protected void btn_Limpiar_Click(object sender, EventArgs e)
        {
            Limpiar_Formulario();
        }

        public void Limpiar_Formulario()
        {
            txt_Razon_Social.Text = "";
            txt_Nota.Text = "";
            txt_Rubro.Text = "";
            txt_Cuit.Text = "";
            txt_Direccion_Sede_Central.Text = "";
        }

        protected void btn_Aceptar_Click(object sender, EventArgs e)
        {
            Grabar_BD();
            Response.Write("<script>alert('Cliente Agregado Con exito');</script>");
            Page.Response.Redirect("ClientesShowTable.aspx");
        }

        public bool Validar_Registros()
        {
            if (txt_Cuit.Text != "" && txt_Direccion_Sede_Central.Text != "" &&  txt_Razon_Social.Text != "" && txt_Rubro.Text != "")
                return true;
            else
            {
                Response.Write("<script>alert('Debe completar todos los campos Obligatorios');</script>");
                return false;
            }
        }

        public void Grabar_BD()
        {
            if (Validar_Registros())
            {
                string Consulta;

                Consulta = "EXEC Clientes_A '" + txt_Razon_Social.Text + "', '" + txt_Direccion_Sede_Central.Text + "' , '" + txt_Cuit.Text + "', '" + txt_Rubro.Text + "', '" + txt_Nota.Text + "'";

                Funciones.Insert_DataBase(Consulta);
            }
        }

        protected void btn_Aceptar_Cargar_Otro_Click(object sender, EventArgs e)
        {
            Grabar_BD();
            Response.Write("<script>alert('Cliente Agregado Con exito');</script>");
            Page.Response.Redirect("ClientesAddEdit.aspx");
        }

    }
}